<?php
include("../models/webconfig.php");
include("../models/class.connection.php");
include("../models/entities/class.AuthorityEntity.php");
include("../models/repositories/class.AuthorityRepository.php");
include("../library/library.pager.php");
$authority = new AuthorityRepository();
$listAuthority = $authority->GetAll();
$list = array();
if (isset($_POST['id'])) {
    $list = $authority->GetAuthoritiesByGroup($_POST['id']);
}
?>

<div class="loading"></div>
<table width="100%">
    <tr class="animate">
        <td class="title">STT</td>
        <td class="title">Mã chức năng</td>
        <td class="title">Tên chức năng </td>
        <td class="title">Ghi chú</td>
    </tr>
    <?php if (isset($listAuthority)) {
    ?>
    <?php if (count($listAuthority) > 0) {
    ?>
    <?php
            for ($i = 0; $i < count($listAuthority); $i++) {
                $check = 0;
                if (count($list) > 0) {
                    for ($j = 0; $j < count($list); $j++) {
                        if ($listAuthority[$i]->ID_i == $list[$j]->ID_i) {
                            $check = 1;
                            break;
                        }
                    }
                }
    ?>
                <tr class="animate">
                    <td><?php echo($i + 1); ?></td>
                    <td><?php echo($listAuthority[$i]->ID_i); ?></td>
                    <td style="text-align:left; padding-left:50px;">
                        <label><?php echo($listAuthority[$i]->Name_s); ?></label>
            <?php if ($check == 0) {
 ?>
                    <input name="check[]" type="checkbox" value="<?php echo($listAuthority[$i]->ID_i); ?>">
<?php } else { ?>
                    <input checked="checked" name="check[]" type="checkbox" value="<?php echo($listAuthority[$i]->ID_i); ?>">
<?php } ?>
            </td>
            <td><?php echo($listAuthority[$i]->Description_s); ?></td>
        </tr>
    <?php } ?>
    <?php } ?>
<?php } ?>
</table>
<p style="font-weight:bold; color:#54A7D8;">Chọn tất cả
    <input type="checkbox" name="checkall" id="checkall"></p>
